package com.schoolcloud.social.controller.event;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.common.model.UserInfo;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.social.entity.SocEventParticipants;
import com.schoolcloud.social.query.EventJoinerQuery;
import com.schoolcloud.social.query.EventParticipantsQuery;
import com.schoolcloud.social.service.EventInteractionService;
import com.schoolcloud.social.service.SocEventParticipantsService;
import com.schoolcloud.social.vo.EventJoinerVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**活动参与者控制器
 * @author hongmizfb
 * @date 2025/08/14
 */
@RestController
@RequestMapping("/social/event/participant")
@RequiredArgsConstructor
public class SocEventParticipantsController {
    private final SocEventParticipantsService socEventParticipantsService;
    private final EventInteractionService eventInteractionService;
    @GetMapping("/page")
    public R<PageDTO<SocEventParticipants>> getEventParticipantsPage(EventParticipantsQuery eventParticipantsQuery) {
        return R.ok(eventInteractionService.getEventParticipantPage(eventParticipantsQuery));
    }
    @PostMapping
    public R addEventParticipants(@RequestBody SocEventParticipants socEventParticipants) {
        eventInteractionService.userJoinEvent(socEventParticipants);
        return R.ok();
    }
    @DeleteMapping("/{id}")
    public R deleteEventParticipants(@PathVariable Integer id) {
        socEventParticipantsService.removeById(id);
        return R.ok();
    }

    /**修改时如果是审核，那么需要新增一条审核记录
     * @param socEventParticipants
     * @return {@link R }
     */
    @PutMapping
    public R updateEventParticipants(@RequestBody SocEventParticipants socEventParticipants) {
        socEventParticipantsService.updateEventParticipants(socEventParticipants);
        return R.ok();
    }
    @GetMapping("/joiner/count")
    public R<Long> getUserJoinEventCount(@RequestParam(required = false)Integer eventId) {
        return R.ok(socEventParticipantsService.getJoinerCount(eventId));
    }

    /**查询活动的参与者
     * @param query
     * @return {@link R }<{@link PageDTO }<{@link UserInfo }>>
     */
    @GetMapping("/joiner/page")
    public R<PageDTO<EventJoinerVO>> getUserJoinEvent(EventJoinerQuery query) {
        return R.ok(eventInteractionService.getEventJoinerPage(query));
    }

}
